#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int N = 2010;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

ll qui(ll a, ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % MOD;
        b >>= 1;
        a = a * a % MOD;
    }
    return res;
}

ll fac[N], inv_fac[N];
ll S[N][N];

void init()
{
    fac[0] = 1;
    for (int i = 1; i < N; i++)
        fac[i] = fac[i - 1] * i % MOD;
    inv_fac[N - 1] = qui(fac[N - 1], MOD - 2);
    for (int i = N - 1; i > 0; i--)
        inv_fac[i - 1] = inv_fac[i] * i % MOD;
    S[0][0] = 1;
    for (int i = 1; i < N; ++i)
    {
        for (int j = 1; j < N; ++j)
        {
            S[i][j] = (j * S[i - 1][j] % MOD + S[i - 1][j - 1]) % MOD;
        }
    }
}

ll comb(int a, int b)
{
    return fac[a] * inv_fac[b] % MOD * inv_fac[a - b] % MOD;
}

// 第一类斯特林数
ll s[N][N];
void sinit()
{
    s[0][0] = 1;
    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= i; ++j)
        {
            s[i][j] = (s[i - 1][j - 1] + (i - 1) * s[i - 1][j]) % MOD;
        }
    }
}

void solve()
{
    int n, m, l;
    cin >> n >> m >> l;
    vector<pii> p1(n), p2(m);
    int a, b;
    for (int i = 0; i < n; i++)
    {
        cin >> a >> b;
        p1[i] = {a, b};
    }
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b;
        p2[i] = {a, b};
    }
    int ans = 0;
    priority_queue<int, vector<int>, less<int>> pq;
    int t = 1, i, j;
    for (i = 0, j = 0; j < m;)
    {
        if (p1[i].first > p2[j].first)
        {
            pq.push(p2[j].second);
            j++;
        }
        else
        {
            int k = p1[i].second - p1[i].first + 2;
            while (pq.size() && t < k)
            {
                t += pq.top();
                pq.pop();
                ans++;
            }
            if (t < k)
            {
                cout << -1 << endl;
                return;
            }
            cout << t << endl;
            i++;
            if (i == n)
            {
                cout << ans << endl;
                return;
            }
        }
    }
    while (i < n)
    {
        int k = p1[i].second - p1[i].first + 2;
        while (pq.size() && t < k)
        {
            t += pq.top();
            pq.pop();
            ans++;
        }
        if (t < k)
        {
            cout << -1 << endl;
            return;
        }
        i++;
    }
    cout << ans << endl;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}